package com.wei.tang.adapter;

import java.util.List;

import com.wei.tang.R;
import com.wei.tang.bean.CourseBean;
import com.wei.tang.util.Tlog;
import com.wei.tang.util.Util;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class TalkInformationItemAdapter extends BaseAdapter {
	private Context mContext;
	private LayoutInflater mInflater;
	private List<CourseBean> datas;
	private int listItemLayout;

	public TalkInformationItemAdapter(Context _context, List<CourseBean> _datas, int _listItemLayout) {
		this.mContext = _context;
		this.datas = _datas;
		this.listItemLayout = _listItemLayout;
	}

	@Override
	public int getCount() {
		return datas.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		CourseBean bean = datas.get(position);
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = View.inflate(mContext, listItemLayout, null);
			holder.iv_talk_info_image = (ImageView) convertView.findViewById(R.id.iv_talk_info_image);
			holder.tv_talk_info_name = (TextView) convertView.findViewById(R.id.tv_talk_info_name);
			holder.tv_talk_info_content = (TextView) convertView.findViewById(R.id.tv_talk_info_content);
			holder.tv_talk_info_time = (TextView) convertView.findViewById(R.id.tv_talk_info_time);
			holder.tv_find_info_way = (TextView) convertView.findViewById(R.id.tv_find_info_way);
			holder.tv_find_info_comment = (TextView) convertView.findViewById(R.id.tv_find_info_comment);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.iv_talk_info_image.setImageResource(Util.getResId(bean.getCourse_size(), R.drawable.class));
		holder.tv_talk_info_name.setText(bean.getCourse_name());
		holder.tv_talk_info_time.setText(bean.getCourse_time());
		holder.tv_find_info_way.setText(bean.getCourse_playtimes());
		holder.tv_find_info_comment.setText(bean.getCourse_id());
		holder.tv_talk_info_content.setText(bean.getCourse_url());

		return convertView;
	}

	private static class ViewHolder {
		private ImageView iv_talk_info_image;
		private TextView tv_talk_info_name;
		private TextView tv_talk_info_content;
		private TextView tv_talk_info_time;
		private TextView tv_find_info_way;
		private TextView tv_find_info_comment;
	}
}